package com.huangkailong.designpattern.facade;

/**
 * 礼物兑换服务门面.
 *
 * @author huangkl
 * @since 1.0.0
 */
public class GiftFacadeService {
    private final QualificationService qualificationService;
    private final PaymentService paymentService;
    private final LogisticsService logisticsService;

    public GiftFacadeService(
        QualificationService qualificationService,
        PaymentService paymentService,
        LogisticsService logisticsService) {
        this.qualificationService = qualificationService;
        this.paymentService = paymentService;
        this.logisticsService = logisticsService;
    }

    /**
     * 兑换礼物.
     *
     * @param giftInfo {@link GiftInfo}
     * @return ture 兑换成功 ,false 兑换失败
     */
    public boolean exchange(GiftInfo giftInfo) {
        if (!qualificationService.isAvailable(giftInfo)) {
            return false;
        }
        if (!paymentService.pay(giftInfo)) {
            return false;
        }
        return logisticsService.delivery(giftInfo);
    }
}
